<template>
  <div>
    <h4>{{ mytitle }}</h4>
    <ul>
      <li v-for="item in goodsList" :key="item.id" @click="goToDetail(item.id)">
        <img v-lazy="item.list_pic_url" alt="" width="100%" style="display: block;">
        <div class="title">{{item.name}}</div>
        <div class="price">{{item.retail_price | filtermoney}}</div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'ProductHome',
  props: ['goodsList', 'mytitle'],
  methods: {
    // 跳转到商品详情页
    async goToDetail(id) {
      await this.$router.push('/productdetail/' + id)
    }
  }
}
</script>

<style lang="less" scoped>
h4 {
  text-align: center;
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  background-color: #fff;
  font-weight: normal;
}
ul {
  background-color: #fff;
  padding: .1rem 2%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  li {
    width: 49%;
    background-color: #fff;
    text-align: center;
    line-height: .3rem;
    margin-bottom: .1rem;
    .title {
      // 最多显示一行的文字，多余的内容会被省略
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .price {
      color: darkred;
    }
  }
}
</style>